<template>
	<view>
		<myhead left="1" txt="我的广告"></myhead>
		<view class="list" v-for="(item,index) in list" :key="index">
			<view>
				<view>{{item.buyType==0?'出售':'购买'}}<span>{{item.type}}</span><span :class="item.status==1?'state1':'state2'">{{item.status==0?'下架':'上架'}}</span></view>
				<view class="czBtn" @tap="czBtn" :data-id="item.id">
					<span></span>
					<span></span>
					<span></span>
				</view>
			</view>
			<view>
				<view class="num">{{item.amount}}CNY</view>
				<view>限额：{{item.minAmount}} - {{item.maxAmount}}CNY</view>
			</view>
			<view>
				<view>{{item.createdTime}}</view>
				<view>数量：{{item.pnumber}} USDT</view>
			</view>
		</view>
		<!-- <view class="list">
			<view>
				<view>出售<span>USDT</span><span :class="false?'state1':'state2'">下架</span></view>
				<view class="czBtn" @tap="czBtn">
					<span></span>
					<span></span>
					<span></span>
				</view>
			</view>
			<view>
				<view class="num">6.00CNY</view>
				<view>限额：20.0000.00 - 320.0000.00CNY</view>
			</view>
			<view>
				<view>2020-12-12 12:12:12</view>
				<view>数量：15.00000000.00 USDT</view>
			</view>
		</view> -->
		<view class="btn" @tap="tjBtn">添加广告</view>
	</view>
</template>

<script>
	const http = require('../../utils/http.js');
	export default {
		data() {
			return {
				state:true,
				list:null
			}
		},
		onShow() {
			uni.showLoading({
			    title: '加载中'
			});
			http.get('/api/purchase/getMyProductList').then(res => {
				//console.log(res)
				if (res.code == 200) {
					this.list=res.result
				}
				uni.hideLoading();
			})
		},
		methods: {
			czBtn:function(e){
				let that=this
				uni.showActionSheet({
				    itemList: ['编辑', '上下架', '删除'],
				    success: function (res) {
				        console.log('选中了第' + (res.tapIndex + 1) + '个按钮');
						if(res.tapIndex==0){
							uni.navigateTo({
								url:'/pages/user/editGuanggao?id='+e.currentTarget.dataset.id
							})
						}
						if(res.tapIndex==1){
							http.get('/api/purchase/onMyProduct',{productId:e.currentTarget.dataset.id}).then(res => {
								//console.log(res)
								if (res.code == 200) {
									uni.showToast({
									  title: res.message,
									  icon: 'none'
									});
									http.get('/api/purchase/getMyProductList').then(res1 => {
										//console.log(res)
										if (res1.code == 200) {
											that.list=res1.result
										}
									})
								}
							})
						}
						if(res.tapIndex==2){
							http.get('/api/purchase/delMyProduct',{productId:e.currentTarget.dataset.id}).then(res => {
								//console.log(res)
								if (res.code == 200) {
									uni.showToast({
									  title: res.message,
									  icon: 'none'
									});
									http.get('/api/purchase/getMyProductList').then(res1 => {
										//console.log(res)
										if (res1.code == 200) {
											that.list=res1.result
										}
									})
								}
							})
						}
				    },
				    fail: function (res) {
				        console.log(res.errMsg);
				    }
				});
			},
			tjBtn:function(){
				uni.navigateTo({
					url:'/pages/user/editGuanggao'
				})
			}
		}
	}
</script>

<style>
	.list{
		padding: 6vw;
		display: flex;
		flex-direction: column;
		border-bottom: 1px solid #F2F2F2;
	}
	.list>view{
		font-size: 3.8vw;
		display: flex;
		flex-direction: row;
		justify-content: space-between;
		align-items: flex-end;
	}
	.list>view:nth-child(1)>view:nth-child(1) span{
		color: #007AFF;
		margin-left: 2vw;
	}
	.list>view:nth-child(2),.list>view:nth-child(3){
		margin-top: 2vw;
		color: #999999;
		font-size: 3.2vw;
	}
	.czBtn span{
		display: inline-block;
		width: 1.6vw;
		height: 1.6vw;
		border-radius: 50vw;
		margin: 0 0.3vw;
		background: #007AFF;
	}
	.num{
		font-size: 5vw;
		font-weight: bold;
		color: #000000;
	}
	.state1{
		font-size: 2vw;
		padding: 0.3vw 1vw;
		background: #007AFF;
		color: #FFFFFF !important;
	}
	.state2{
		font-size: 2vw;
		padding: 0.3vw 1vw;
		background: #DD524D;
		color: #FFFFFF !important;
	}
	.btn{
		width: 84%;
		padding: 4vw 0;
		font-size: 3.5vw;
		border-radius: 1.8vw;
		background-image: linear-gradient(45deg, #24EBA9, #10C7B2);
		color: #FFFFFF;
		text-align: center;
		margin: 0 auto;
		margin-top: 10vw;
	}
</style>
